import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import path from 'path';
import viteImagemin from 'vite-plugin-imagemin'

// TODO 把其他能想到的优化做完之后就尝试一下迁移到Nuxt3做一下SSR
// TODO 尝试SEO优化
// TODO 尝试使用https

// https://vitejs.dev/config/
export default defineConfig({
  esbuild: {
    logLevel: 'silent', // 关闭 esbuild 警告
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  plugins: [
    vue(),
    AutoImport({
      imports:['vue','vue-router'],
      dts: 'src/auto-import.d.ts',
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    viteImagemin({
      optipng: {
        optimizationLevel: 7, // 优化级别 0 ~ 7，数值越高压缩越强
      },
      pngquant: {
        quality: [0.7, 0.9], // PNG 压缩质量范围
        speed: 3             // 压缩速度（1 最慢但最优质，10 最快但最差）
      },
      gifsicle: {
        optimizationLevel: 3,
      },
      mozjpeg: {
        quality: 75, // 只对 JPEG 生效
      },
      webp: {
        quality: 75,
      },
    })
  ],
  server:{
    proxy:{
      '/api':{
        target:'http://localhost:8080',
        changeOrigin:true,
        rewrite:path=>path.replace(/^\/api/,'')
      }
    }
  }
})


